<template>
  <div class="login-main changePsd-main">
    <div class="com-header change-psd">
      <button @click="$router.go(-1)"><i></i></button>
      <span>修改密码</span>
    </div>
    <!-- 网页内容区域 -->
    <div class="view-content">
        <img class="logo" src="~assets/image/login/logo.png" alt="快眼看书logo">

        <div class="form-wrapper">
            <div class="input-item">
                <i class="psd-icon"></i><input type="password" v-model="password_old" placeholder="请输入旧密码">
            </div>
            <div class="input-item">
                <i class="psd-icon"></i><input type="password" v-model="password_new" placeholder="请输入新密码">
            </div>
            <div class="input-item">
                <i class="psd-icon"></i><input type="password" v-model="password_new_confirmation" placeholder="请再次输入密码">
            </div>
        </div>
        <div class="submitBtn">
            <button @click="submitMethod">修改</button>
        </div>
    </div>
  </div>
</template>

<script>
  import {Toast} from 'mint-ui'
  import api from '~/plugins/api.js'
  import axios from 'axios'
  import qs from 'qs'
  import storage from 'localforage'
  export default {
    head: {
      title: '修改密码  - 快眼看书',
      meta: [{
            name: 'description',
            content: '快眼看书专注于玄幻小说搜索,新版快眼看书,提供最全的小说保持最快的更新,方便大家愉快地阅读玄幻小说'
        },{
            name: 'keyWords',
            content: '修改密码,快眼看书'
      }]
    },
    data () {
      return {
         password_old: '',
         password_new: '',
         password_new_confirmation: ''
      }
    },
    mounted() {
       
    },
    methods: {
        // 确定按钮监听
        submitMethod() {    
            this.updatepsd()
        },
        async updatepsd() {
            let _this = this
            let userInfo = await storage.getItem('userinfo')
            if(userInfo){
                let paramsData = {
                    password_old: this.password_old,
                    password_new: this.password_new,
                    password_new_confirmation: this.password_new_confirmation
                }
                let result = await axios.post(api.changePassword+`?token=${userInfo.token}&uid=${userInfo.uid}`,qs.stringify(paramsData))
                if(result.data.status==1){
                    let clear = await storage.removeItem('userinfo')
                    this.$router.push('/loginReg')
                }else{
                    Toast(result.data.info)
                }
            }else{
                Toast('请先登录')
            }
            
        }
    },
    components: {
     
    }
  }
</script>
<style lang="scss">
    .changePsd-main{
       .view-content{
            top: 1.24rem!important;
        }
        .change-psd{
            border-bottom: 1px solid #eeeeee!important;
            span{
                position: absolute;
                bottom: 0;
                left: 4.3rem;
            }
        } 
    }
</style>
